package com.nineclock.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nineclock.common.constant.NcConstant;
import com.nineclock.common.utils.CurrentUserHolder;
import com.nineclock.system.dto.SysCompanyUserDTO;
import com.nineclock.system.mapper.SysCompanyUserMapper;
import com.nineclock.system.pojo.SysCompanyUser;
import com.nineclock.system.service.SysCompanyUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class SysCompanyUserServiceImpl extends ServiceImpl<SysCompanyUserMapper, SysCompanyUser> implements SysCompanyUserService {
    @Autowired
    private SysCompanyUserMapper companyUserMapper;
    @Override
    public SysCompanyUserDTO getCurrentAdmin() {
        Long companyId = CurrentUserHolder.get().getCompanyId();
        SysCompanyUser companyUser = companyUserMapper.getCurrentAdmin(companyId, NcConstant.ADMIN_ROLE_SYS);
        SysCompanyUserDTO dto = new SysCompanyUserDTO();
        BeanUtils.copyProperties(companyUser,dto);
        return dto;
    }

    /**
     * 查找当前企业员工
     * @return
     */
    @Override
    public List<SysCompanyUser> getMembers() {
        Long companyId = CurrentUserHolder.get().getCompanyId();
        LambdaQueryWrapper<SysCompanyUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysCompanyUser::getCompanyId,companyId).eq(SysCompanyUser::getEnable,1);
        List<SysCompanyUser> list = this.list(wrapper);
        return list;
    }
}
